package protocol.SZ_2021;

public class SZ_2021Utils {

    public static String toDeviceType(int type){
        switch (type){
            case 1:
                return "通讯模块(GPRS/CDMA)";
            case 2:
                return "计价器";
            case 3:
                return "出租汽车安全模块";
            case 4:
                return "LED显示屏";
            case 5:
                return "智能顶灯";
            case 6:
                return "服务评价器(后排)";
            case 7:
                return "摄像头";
            case 8:
                return "卫星定位设备";
            case 9:
                return "液晶（LCD）多媒体屏";
            case 10:
                return "多功能信息显示屏(含评价)";
            case 11:
                return "服务评价器（前排）";
            case 12:
                return "支付装置";
            case 13:
                return "ETC设备";
            default:
                return "未定义/RFU";
        }
    }

    public static void handle0200ALL(StringBuilder builder, SZ_2021Cmd cmd){

        handle0200Base(cmd, builder);

        if (cmd.leftSize() > 2){
            while (cmd.leftSize() > 2){
                int id = cmd.readInt(1);
                int size = cmd.readInt(1);
                switch (id){
                    case 0x01:
                        builder.append("里程："+cmd.readInt(4));
                        builder.append("\r\n");
                        break;
                    case 0x02:
                        builder.append("油量："+cmd.readInt(2));
                        builder.append("\r\n");
                        break;
                    case 0x03:
                        builder.append("海拔高度："+cmd.readInt(2));
                        builder.append("\r\n");
                        break;
                    case 0x11:
                        builder.append("超速报警附加信息："+cmd.readBCD(size));
                        builder.append("\r\n");
                        break;
                    case 0x12:
                        builder.append("进出区域/路线报警附加信息："+cmd.readBCD(size));
                        builder.append("\r\n");
                        break;
                    case 0x13:
                        builder.append("路段行驶时间不足/过长报警附加信息："+cmd.readBCD(size));
                        builder.append("\r\n");
                        break;
                    case 0x14:
                        builder.append("禁行路段行驶报警附加信息："+cmd.readBCD(size));
                        builder.append("\r\n");
                        break;
                    case 0x15:
                        builder.append("车牌号码："+cmd.readString(size));
                        builder.append("\r\n");
                        break;
                    case 0xC4:
                        builder.append("报警/事件类型："+cmd.readBCD(size));
                        builder.append("\r\n");
                        break;
                    case 0xC5:
                        builder.append("CAN 数据异常报警："+cmd.readBCD(size));
                        builder.append("\r\n");
                        break;
                    case 0xD6:
                        builder.append("剩余电量 S0C 0~100："+cmd.readInt(size));
                        builder.append("\r\n");
                        break;
                    case 0xDC:
                        builder.append("车辆状态："+cmd.readInt(size));
                        builder.append("\r\n");
                        break;
                    case 0xDE:
                        builder.append("开关门信息："+cmd.readInt(size));
                        builder.append("\r\n");
                        break;
                    case 0xF7:
                        builder.append("当前车内乘客人数（不算司机）："+cmd.readInt(size));
                        builder.append("\r\n");
                        break;
                }

            }
        }
    }

    public static void handle0200Base(SZ_2021Cmd cmd, StringBuilder builder){
        int warn = cmd.readInt(4);
        builder.append("\r\n");
        builder.append("--------------基本位置信息-----------------");
        builder.append("\r\n");
        builder.append("报警信息:"+warn);
        builder.append("\r\n");
        builder.append("    紧急报警："+(warn&0x01));
        builder.append("\r\n");
        builder.append("    预警："+(warn>>1&0x01));
        builder.append("\r\n");
        builder.append("    卫星定位模块发生故障："+(warn>>2&0x01));
        builder.append("\r\n");
        builder.append("    卫星定位天线未接或被剪断："+(warn>>3&0x01));
        builder.append("\r\n");
        builder.append("    卫星定位天线短路："+(warn>>4&0x01));
        builder.append("\r\n");
        builder.append("    终端主电源欠压："+(warn>>5&0x01));
        builder.append("\r\n");
        builder.append("    终端主电源掉电："+(warn>>6&0x01));
        builder.append("\r\n");
        builder.append("    智能服务终端人机交互设备故障："+(warn>>7&0x01));
        builder.append("\r\n");
        builder.append("    语音合成（TTS）模块故障："+(warn>>8&0x01));
        builder.append("\r\n");
        builder.append("    摄像头故障："+(warn>>9&0x01));
        builder.append("\r\n");
        builder.append("    计程计价装置故障："+(warn>>10&0x01));
        builder.append("\r\n");
        builder.append("    服务评价器故障："+(warn>>11&0x01));
        builder.append("\r\n");
        builder.append("    LED广告屏故障："+(warn>>12&0x01));
        builder.append("\r\n");
        builder.append("    液晶（终端）显示屏故障："+(warn>>13&0x01));
        builder.append("\r\n");
        builder.append("    安全访问模块故障："+(warn>>14&0x01));
        builder.append("\r\n");
        builder.append("    顶灯故障："+(warn>>15&0x01));
        builder.append("\r\n");
        builder.append("    超速报警："+(warn>>16&0x01));
        builder.append("\r\n");
        builder.append("    连续驾驶超时："+(warn>>17&0x01));
        builder.append("\r\n");
        builder.append("    当天累计驾驶超时："+(warn>>18&0x01));
        builder.append("\r\n");
        builder.append("    超时停车："+(warn>>19&0x01));
        builder.append("\r\n");
        builder.append("    进出区域/路线："+(warn>>20&0x01));
        builder.append("\r\n");
        builder.append("    路段行驶时间不足/过长："+(warn>>21&0x01));
        builder.append("\r\n");
        builder.append("    禁行路段行驶："+(warn>>22&0x01));
        builder.append("\r\n");
        builder.append("    车速传感器故障："+(warn>>23&0x01));
        builder.append("\r\n");
        builder.append("    车辆非法点火："+(warn>>24&0x01));
        builder.append("\r\n");
        builder.append("    车辆非法位移："+(warn>>25&0x01));
        builder.append("\r\n");
        builder.append("    智能终端存储异常："+(warn>>26&0x01));
        builder.append("\r\n");
        builder.append("    录音设备故障："+(warn>>27&0x01));
        builder.append("\r\n");
        builder.append("    支付装置故障："+(warn>>28&0x01));
        builder.append("\r\n");
        builder.append("    不打表营运："+(warn>>29&0x01));
        builder.append("\r\n");
        builder.append("    智能识别服务器异常："+(warn>>30&0x01));

        builder.append("\r\n");
        builder.append("\r\n");

        int status = cmd.readInt(4);
        builder.append("状态信息:"+status);
        builder.append("\r\n");
        builder.append("    停运状态："+(status&0x01));
        builder.append("\r\n");
        builder.append("    电召状态："+(status>>1&0x01));
        builder.append("\r\n");
        builder.append("    未卫星定位："+(status>>2&0x01));
        builder.append("\r\n");
        builder.append("    南北纬（1为北）："+(status>>3&0x01));
        builder.append("\r\n");
        builder.append("    东西经（1为西）："+(status>>4&0x01));
        builder.append("\r\n");
        builder.append("    空转重（0为默认）："+(status>>5&0x01));
        builder.append("\r\n");
        builder.append("    重转空（0为默认）："+(status>>6&0x01));
        builder.append("\r\n");
        builder.append("    预留："+(status>>7&0x01));
        builder.append("\r\n");
        builder.append("    ACC："+(status>>8&0x01));
        builder.append("\r\n");
        builder.append("    空重车（1为重）："+(status>>9&0x01));
        builder.append("\r\n");
        builder.append("    车辆油路断开："+(status>>10&0x01));
        builder.append("\r\n");
        builder.append("    车辆电路断开："+(status>>11&0x01));
        builder.append("\r\n");
        builder.append("    车门加锁："+(status>>12&0x01));
        builder.append("\r\n");
        builder.append("    智能终端锁定："+(status>>13&0x01));
        builder.append("\r\n");
        builder.append("    已达到限制营运次数/时间："+(status>>14&0x01));
        builder.append("\r\n");
        builder.append("    计程计价装置锁定："+(status>>15&0x01));
        builder.append("\r\n");
        builder.append("    车辆CAN数据异常："+(status>>16&0x01));
        builder.append("\r\n");
        builder.append("    下班（交接班）状态："+(status>>17&0x01));
        builder.append("\r\n");
        builder.append("    前往充电状态："+(status>>18&0x01));
        builder.append("\r\n");
        builder.append("    连续空车时长报警："+(status>>19&0x01));
        builder.append("\r\n");
        builder.append("    紧急报警按钮故障："+(status>>20&0x01));
        builder.append("\r\n");
        builder.append("    打印机故障："+(status>>21&0x01));
        builder.append("\r\n");
        builder.append("    ETC设备故障："+(status>>22&0x01));
        builder.append("\r\n");
        builder.append("\r\n");
        builder.append("纬度："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("经度："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("速度(百米/H)"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("方向："+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("时间："+cmd.readBCD(6));
        builder.append("\r\n");

        builder.append("-------------------------------------------");
        builder.append("\r\n");
    }

}
